package com.zuofei.xmpp;

import android.content.ContentValues;
import android.database.Cursor;
import android.support.test.runner.AndroidJUnit4;

import com.elvishew.xlog.XLog;
import com.github.stuxuhai.jpinyin.PinyinFormat;
import com.github.stuxuhai.jpinyin.PinyinHelper;
import com.zuofei.xmpp.dbhelper.ContactOpenHelper;
import com.zuofei.xmpp.provider.ContactsProvider;

import org.junit.Test;
import org.junit.runner.RunWith;

@RunWith(AndroidJUnit4.class)
public class TestContactsProvider {

    @Test
    public void testInsert(){
        ContentValues values = new ContentValues();
        values.put(ContactOpenHelper.ContactTable.ACCOUNT,"billy@itheima.com");
        values.put(ContactOpenHelper.ContactTable.NICKNAME,"老五");
        values.put(ContactOpenHelper.ContactTable.AVATAR,"0");
        values.put(ContactOpenHelper.ContactTable.PINYIN,"laowu");
        XmppApplication.getInstance().getContentResolver().insert(ContactsProvider.URI_CONTACT,values);
    }

    @Test
    public void testDelete(){
        XmppApplication.getInstance().getContentResolver().delete(ContactsProvider.URI_CONTACT,ContactOpenHelper.ContactTable.ACCOUNT+"=?",new String[]{"billy@itheima.com"});
    }
    @Test
    public void testUpdate(){
        ContentValues values = new ContentValues();
        values.put(ContactOpenHelper.ContactTable.ACCOUNT,"billy@itheima.com");
        values.put(ContactOpenHelper.ContactTable.NICKNAME,"我是老五");
        values.put(ContactOpenHelper.ContactTable.AVATAR,"0");
        values.put(ContactOpenHelper.ContactTable.PINYIN,"laowu");
        XmppApplication.getInstance().getContentResolver().update(ContactsProvider.URI_CONTACT,values,ContactOpenHelper.ContactTable.ACCOUNT+"=?",new String[]{"billy@itheima.com"});
    }
    @Test
    public void testQuery(){
       Cursor c = XmppApplication.getInstance().getContentResolver().query(ContactsProvider.URI_CONTACT,null,null,null);
       int columnCount =  c.getColumnCount();
       while (c.moveToNext()){
            for(int i = 0; i < columnCount;i++){
                XLog.d(c.getString(i));
            }
       }
    }

    @Test
    public void pinyin(){
      String pinyin =  PinyinHelper.convertToPinyinString("黑马程序员","", PinyinFormat.WITHOUT_TONE);
      XLog.d(pinyin);
    }
}
